package tech.aistar.wyymusicplayer.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tech.aistar.wyymusicplayer.mapper.PlayListDetailsMapper;
import tech.aistar.wyymusicplayer.mapper.PlaylistMapper;
import tech.aistar.wyymusicplayer.mapper.SongMapper;
import tech.aistar.wyymusicplayer.pojo.Song;

import java.util.List;

@Service
public class SongServiceImpl implements SongService{

    @Autowired
    private PlayListDetailsMapper playlistSongMapper;

    @Autowired
    private SongMapper songMapper;

    @Override
    public Song selectById(Integer songId) {
       return songMapper.selectById(songId);

    }

    @Override
    public Song findSongById(Integer songId) {
        return songMapper.findById(songId);

    }

    @Override
    public List<Song> selectByTitle(String songName) {
        return songMapper.selectByTitle(songName);
    }

    @Override
    public List<Song> selectByArtist(String name) {
        return songMapper.selectByArtist(name);
    }

    @Override
    public List<Song> getSongsByPlaylistId(Integer playlistId) {
        // 1. 获取歌曲ID列表
        List<Integer> songIds = playlistSongMapper.selectSongIdsByPlaylistId(playlistId);

        // 2. 批量查询歌曲
        return songMapper.selectSongsByIds(songIds);
    }
}
